package com.java.tutorials.jdk7.paths;

import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * Created by xuzhike on 2016/1/27.
 * http://www.java2s.com/Code/Java/JDK-7/Checkexistancewithoutfollowingthesymboliclinks.htm
 * Check existance without following the symbolic links
 */
public class Checkexistancewithoutsymboliclinks {
    public static void main(String[] args) throws Exception {
        Path firstPath = Paths.get("/home/music/users.txt");
        Path secondPath = Paths.get("/docs/status.txt");
        System.out.println("From firstPath to secondPath: "
                + firstPath.relativize(secondPath));
        System.out.println("From secondPath to firstPath: "
                + secondPath.relativize(firstPath));
        System.out.println("exists (Do not follow links): "
                + Files.exists(firstPath, LinkOption.NOFOLLOW_LINKS));
        System.out.println("exists: " + Files.exists(firstPath));
        System.out.println("notExists (Do not follow links): "
                + Files.notExists(firstPath, LinkOption.NOFOLLOW_LINKS));
        System.out.println("notExists: " + Files.notExists(firstPath));

    }
}
